package com.yyfax.pay.depository.controller.api;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.yyfax.framework.common.OpResponse;
import com.yyfax.pay.common.annotation.CheckSign;
import com.yyfax.pay.common.model.to.YYPayApiReq2;
import com.yyfax.pay.depository.service.inner.FuiouQueryService;
import com.yyfax.pay.service.depository.BalanceQueryService;
import com.yyfax.pay.vo.depository.BalanceQueryReq;
import com.yyfax.pay.vo.depository.QueryChangeCardReq;
import com.yyfax.pay.vo.depository.QueryChargeWithdrawReq;
import com.yyfax.pay.vo.depository.QueryTradeReq;
import com.yyfax.pay.vo.depository.QueryTransferChargeReq;
import com.yyfax.pay.vo.depository.QueryTransferChargeRsp;
import com.yyfax.pay.vo.depository.QueryUserInfoReq;

/**
 * 查询接口
 *
 * @author heizq
 * @date 2017-09-08 15:10:50
 * @since v1.0.0
 */
@RestController
public class QueryApiController {

	@Resource
	private BalanceQueryService balanceQueryService;
	@Resource
	private FuiouQueryService fuiouQueryService;

	/**
	 * 余额查询
	 *
	 * @author heizq
	 * @date 2017-09-08 15:21:12
	 * @since v1.0.0
	 * @param req
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/api/fuiou/query/balance")
	@CheckSign
	public OpResponse balanceQuery(@Valid @RequestBody YYPayApiReq2<BalanceQueryReq> req) throws Exception {
		OpResponse response = OpResponse.success();

		response.setContent(balanceQueryService.balanceQuery(req.getMerchantCode(), req.getParams()));
		return response;
	}

	/**
	 * 充值提现查询
	 *
	 * @author yejc
	 * @date 2017-09-20
	 * @since v2.0.0
	 * @param req
	 * @return
	 */
	@PostMapping("/api/fuiou/query/charge_withdraw")
	@CheckSign
	public OpResponse queryChargeWithdraw(@RequestBody @Valid YYPayApiReq2<QueryChargeWithdrawReq> req) {
		OpResponse opResponse = OpResponse.success();
		opResponse.setContent(fuiouQueryService.queryChargeWithdraw(req.getMerchantCode(), req.getParams()));
		return opResponse;
	}

	/**
	 * 用户更换银行卡查询
	 *
	 * @author yejc
	 * @date 2017-09-20
	 * @since v2.0.0
	 * @param req
	 * @return
	 */
	@PostMapping("/api/fuiou/query/change_card")
	@CheckSign
	public OpResponse queryChangeCard(@RequestBody @Valid YYPayApiReq2<QueryChangeCardReq> req) {
		OpResponse success = OpResponse.success();
		success.setContent(fuiouQueryService.queryChangeCard(req.getMerchantCode(), req.getParams()));
		return success;
	}

	/**
	 * 用户信息查询
	 *
	 * @author yejc
	 * @date 2017-09-20
	 * @since v2.0.0
	 * @param req
	 * @return
	 */
	@PostMapping("/api/fuiou/query/user_info")
	@CheckSign
	public OpResponse queryUserInfo(@RequestBody @Valid YYPayApiReq2<QueryUserInfoReq> req) {
		OpResponse success = OpResponse.success();
		success.setContent(fuiouQueryService.queryUserInfo(req.getMerchantCode(), req.getParams()));
		return success;
	}

	/**
	 * 交易查询
	 *
	 * @author yejc
	 * @date 2017-09-20
	 * @since v2.0.0
	 * @param req
	 * @return
	 */
	@PostMapping("/api/fuiou/query/trade")
	@CheckSign
	public OpResponse queryTrade(@RequestBody @Valid YYPayApiReq2<QueryTradeReq> req) {
		OpResponse success = OpResponse.success();
		success.setContent(fuiouQueryService.queryTrade(req.getMerchantCode(), req.getParams()));
		return success;
	}

	/**
	 * 转账充值查询
	 *
	 * @author wujiande
	 * @date 2018-05-21 17:44:34
	 * @since v2.1.7
	 * @param req
	 * @return
	 */
	@PostMapping("/api/fuiou/query/transfer_charge")
	@CheckSign
	public OpResponse queryTransferCharge(@RequestBody @Valid YYPayApiReq2<QueryTransferChargeReq> req) {
		OpResponse success = OpResponse.success();
		req.getParams().validate();
		QueryTransferChargeRsp content = fuiouQueryService.queryTransferCharge(req.getMerchantCode(), req.getParams());
		success.setContent(content);
		return success;
	}
}
